import { PURCHASE_TYPE } from '@/pages/commodity/commodityInfoEdit/saleAreaManage/saleAreaAdd/constants';

const state = {
  batchSetDataVo: {
    costPriceRatio: null, // 成本比例
    templateCityUuid: '', // 参照城市uuid
    templateCityName: '', // 参照城市名称
  },
  referCitiesOptions: [], // 选择城市的下拉框数据
  checkedSupplyCityCodes: [], // 已勾选的供货城市编码集合
  supplyCitiesOptions: [], // 供货城市集合
  purchaseType: PURCHASE_TYPE.Unify, // 进价类型
}

const getters = {
  // 是否主供
  isSupply: (state, getters) => cityInfo => {
    const isFlag = state.checkedSupplyCityCodes.includes(cityInfo.saleCityUuid) // 当前城市编码存在于供货城市编码集合中，即该城市为供货城市
    return isFlag
  },
  // 是否是统一进价
  isUnify: (state, getters) => () => {
    const isFlag = state.purchaseType == PURCHASE_TYPE.Unify
    return isFlag
  }
}

const mutations = {
  // 更新批量设置数据
  UPDATE_BATCH_SET_DATA_VO: (state, data) => {
    state.batchSetDataVo = {
      ...state.batchSetDataVo,
      ...data
    }
  },
  // 更新已勾选的供货城市编码集合
  UPDATE_REFER_CITIES_OPTIONS: (state, data) => {
    state.referCitiesOptions = [...data]
  },
  // 更新已勾选的供货城市编码集合
  UPDATE_CHECKED_SUPPLY_CITY_CODES: (state, data) => {
    state.checkedSupplyCityCodes = [...data]
  },
  // 更新供货城市集合
  UPDATE_SUPPLY_CITIES_OPTIONS: (state, data) => {
    state.supplyCitiesOptions = [...data]
  },
  // 更新进价类型
  UPDATE_PURCHASE_TYPE: (state, data) => {
    state.purchaseType = data
  },
}

export default {
  namespaced: true,
  state,
  getters,
  mutations
}
